package projectOne.taoCan;

import projectOne.*;
import projectOne.service.CallService;
import projectOne.service.NetService;
import projectOne.service.SendService;

public class ChatterBoxPackage extends ServicePackage implements CallService, NetService, SendService {
    private int talkTime;
    private int smsCount;
    private int flow;

    public ChatterBoxPackage() {
        super(58);
        this.talkTime = 500;
        this.smsCount =30;
        this.flow =0;
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    public int getFlow() {
        return flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }

    @Override
    public void call(int time, MobileCard card) {
        int temp=1;
        while (temp++<=time){
            if (talkTime-card.getRealTalkTime()>=1){
                card.setRealTalkTime(card.getRealTalkTime()+1);
            } else {
                card.setRealTalkTime(card.getRealTalkTime()+1);
                card.setMoney(card.getMoney()-0.2);
                card.setConsumAmount(card.getConsumAmount()+0.2);
            }
        }
    }

    @Override
    public void net(int flow, MobileCard card) {
            card.setRealFlow(card.getRealFlow()+flow);
            card.setMoney(card.getMoney()-2*flow);
            card.setConsumAmount(card.getConsumAmount()+2*flow);
    }

    @Override
    public void send(int count, MobileCard card) {
        int temp=1;
        while (temp++<=count){
            if (smsCount-card.getRealSMSCount()>=1){
                card.setRealSMSCount(card.getRealSMSCount()+1);
            } else {
                card.setRealSMSCount(card.getRealSMSCount()+1);
                card.setMoney(card.getMoney()-0.1);
                card.setConsumAmount(card.getConsumAmount()+0.1);
            }
        }
    }

    @Override
    public String toString() {
        return "通话时长："+talkTime+"\n短信条数："+smsCount+"\n流量："+flow/1024+"G"+"\n资费："+super.getPrice();
    }
}
